package com.atguigu.guli.service.ucenter.controller.api;

import com.atguigu.guli.service.base.handler.GuliException;
import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.base.result.ResultCodeEnum;
import com.atguigu.guli.service.base.utils.JwtHelper;
import com.atguigu.guli.service.base.utils.JwtInfo;
import com.atguigu.guli.service.ucenter.controller.util.WxOpenProperties;
import com.atguigu.guli.service.ucenter.entity.Member;
import com.atguigu.guli.service.ucenter.service.MemberService;
import com.atguigu.utils.HttpClientUtils;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.Map;
import java.util.UUID;

@RequestMapping("/api/ucenter/wx")
@Controller
public class ApiWxLoginController {
    @Autowired
    MemberService memberService ;
    @Value("${server.port}")
    Integer port ;

    //session中存入数据
    @PostMapping("save")
    public String set(HttpSession session) {
        session.setAttribute("beauty","Amanda");
        return "hahaha" ;
    }
    //session中取出数据
    @GetMapping("get")
    public String get(HttpSession session) {
        Object beauty = session.getAttribute("beauty");
        System.out.println(port+"服务器获取到的数据beauty："+beauty);
        return "hahaha" ;
    }
    //回调
    @GetMapping("callback")
    public String callback(String code , String state , HttpSession session)  {
        String url = memberService.callback(code,state,session) ;
        return url ;

    }

    //生成二维码
    @GetMapping("login")
    public String wxLogin(HttpSession session) {
        String url = memberService.wxLogin(session) ;
        return url ;
    }
}
